|
|
 |
|
|
|
|
Next i
End Sub
' Draw the bar chart. Private Sub Form_Paint()
Dim i As Integer
'Define the custom coordinate system. ScaleLeft = 0
ScaleWidth = NUM_VALUES + 2
ScaleTop = 110
ScaleHeight = -120
' Clear the form. Cls
' Draw the bar chart. For i = 1 To NUM_VALUES
' Pick a new fill style. FillStyle = i Mod 8
' Draw a box with i <= X <= i + 1 and ' 0 <= Y <= Data(i). Line (i, 0)-(i + 1, DataValue(i)), , B
Next i
End Sub |
|
|
|
|
|
|
|
|
To make creating custom coordinate systems easier, Visual Basic provides a Scale method. This routine takes as parameters the coordinates you want to give the upperleft and lower-right corners of the drawing area. For example, to create a custom coordinate system with the upper-left corner at (0, 0) and the lower-right corner at (100, 10), a program could use the single statement: |
|
|
|
 |
|
|
|
|
Scale (0, 0)-(100, 10) |
|
|
|
|
|
|
|
|
This method is usually easier to understand than the ScaleLeft, ScaleTop, ScaleWidth, and ScaleHeight properties. Unfortunately, recent versions of Visual Basic do not allow the coordinates of the lower-right point to be smaller than the coordinates of the upper-left point. For example, if you execute the statement Scale (0, 100)-(100, 0), Visual Basic switches the Y coordinate arguments and treats the statement as if it were Scale (0, 0)-(100, 100). |
|
|
|
|
|
|
|
|
This means you cannot use the Scale method to define the more intuitive coordinate systems where small Y values are near the bottom of the drawing object and larger values are near the top. You must use the ScaleLeft, ScaleTop, ScaleWidth, and ScaleHeight properties individually instead. |
|
|
|
|
|
|
|
|
However, you can write a subroutine similar to the SetScale method to make defining the coordinate system easier. The SetTheScale routine shown in the following code sets a drawing object's Scale properties. The first parameter is the form, picture box, or printer object that should have the new coordinate system. |
|
|
|
|
|